<#import "/manage/tpl/pageBase.ftl" as page>
<@page.pageBase currentMenu="生成邀请码">
<script type="text/javascript">
	$(function() {
		 $("#password").focus();
	});

	function onSubmit() {
		if ($.trim($("#password").val()) == "") {
			alert("旧密码不能为空!");
			$("#password").focus();
			return false;
		}
//
	}
</script>
    <form name="form" action="${basepath}/manage/user/handleInviteCode" method="post">
		<table class="table table-bordered" >
			<tr>
				<td colspan="2" style="background-color: #dff0d8;text-align: center;">
					<strong>邀请码</strong>
				</td>
			</tr>
			<tr style="display:none;">
				<th>id</th>
				<td><input type="hidden" value="${e.id}" name="id"></td>
			</tr>
			<tr>
				<th style="text-align: right; padding-top: 15px">邀请码</th>
				<td style="text-align: left;"><input type="text" name="inviteCode" value="${e.inviteCode}"
						id="inviteCode" disabled="true" /></td>
			</tr>
            <tr>
                <th style="text-align: right; padding-top: 17px">分享邀请码链接</th>
                <td style="text-align: left;">
					<textarea disabled="true" style="width: 500px" name="inviteCodeLink"  id="inviteCodeLink">
					</textarea>

            </tr>
			<tr>
				<td colspan="2" style="text-align: center;">
					<input type="button" onclick="sendVCode(this)" class="btn btn-success" value="重新生成邀请码">
						<i class="icon-ok icon-white"></i>
					</input>
				</td>
			</tr>


		</table>

        </form>
<script type="text/javascript">

    document.getElementById("inviteCodeLink").value = "http://" + window.location.host + "/jshop/account/register?inviteCode="+ document.getElementById("inviteCode").value;

    function sendVCode(obj){
        var _url = "handleInviteCode";
        $.ajax(_url,{
            type: 'POST',
            data: $('#form').serialize(),
            success: function(data){
                document.getElementById("inviteCode").value = data;
                document.getElementById("inviteCodeLink").value = "http://" + window.location.host + "/jshop/account/register?inviteCode="+ data;
                alert("重新生成邀请码成功");
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert("操作失败，请稍后重试!");
            }
        });

    }
</script>
</@page.pageBase>